#pragma once
#ifndef __G_SPIN_MUTEX_H__
#define __G_SPIN_MUTEX_H__

#include <atomic>

#include "GTypes.h"

namespace GThread
{
	class CACHELINE_ALIGNED GSpinMutex
	{
	typedef std::atomic<GUInt32> LockType;
	
	private:
		LockType	Owner;

		void		InternalFree(GUInt32 ThreadId);
		bool		InternalAcquire(GUInt32 ThreadId);

	public:
					GSpinMutex();
					~GSpinMutex();

					GSpinMutex(const GSpinMutex& Other);
		GSpinMutex& operator=(const GSpinMutex& Other);

		void		Free();

		void		Acquire();
		bool		TryAcquire();

		bool		IsLocked();

	};
}

#endif